Pixel Formats topic
A PixelFormat is a description of how pixel data is stored in memory. It
includes a set of standard properties and rules for how to interpret the data,
such as how many bytes are used to store each pixel, canonical (zero or max)
values, and conversion rules to and from other formats.
Pxl ships with a number of built-in pixel formats, and can be extended with additional formats:
const myFormat = const MyFormat._();
// Pixel data type Channel data type
// v v
final class MyFormat extends PixelFormat<int, int> {
const MyFormat._();
@override
int get bytesPerPixel => 4;
@override
int get zero => 0;
// ... rest of the class implementation
}
Integer pixel formats
All integer formats use the ABGR 32-bit format as a common intermediate for
conversions; channels that are larger or smaller than 8 bits are scaled to fit
within the 8-bit range. For example a 4-bit channel value of 0x0F would be
scaled to 0xFF when converting to 8-bit.
| Name | Bits per pixel | Description |
|---|---|---|
| abgr8888 | 32 | 4 channels @ 8 bits each |
| argb8888 | 32 | 4 channels @ 8 bits each |
| gray8 | 8 | 1 channel @ 8 bits |
| rgba8888 | 32 | 4 channels @ 8 bits each |
Grayscale formats use luminance values to represent color.
Floating-point pixel formats
All floating-point formats use the RGBA 128-bit format as a common intermediate
for conversions; channels that are larger or smaller than 32 bits are scaled to
fit within the 32-bit range. When converting to packed integer formats, data is
normalized to the range [0.0, 1.0] and then scaled to fit within the integer
range.
| Name | Bits per pixel | Description |
|---|---|---|
| floatRgba | 128 | Red, Green, Blue, Alpha |
Indexed pixel formats
IndexedFormats use a palette to map pixel values to colors.
The palette is stored as a separate array of colors, and the pixel data is stored as indices into the palette.
// Example of a 1-bit indexed format.
final mono1 = IndexedPixelFormat.bits8(
const [0xFF000000, 0xFFFFFFFF],
format: abgr8888,
);
| Name | Bits per pixel | Description |
|---|---|---|
| system8 | 8 | 8 colors. |
| system256 | 8 | 256 colors (216 RGB + 40 grayscale). |
Classes
- Abgr8888 Pixel Formats
- 32-bit ABGR pixel format with four 8-bit channels.
- Argb8888 Pixel Formats
- 32-bit ARGB pixel format with four 8-bit channels.
- FloatRgba Pixel Formats
- A 128-bit floating-point RGBA pixel format with four 32-bit channels.
- Gray8 Pixel Formats
- 8-bit grayscale pixel format.
-
IndexedFormat<
P> Pixel Formats - A pixel format that uses a predefined palette to index colors.
-
PixelFormat<
P, C> Pixel Formats -
Describes the organization and characteristics of pixel data
Pin memory. -
Rgb<
P, C> Pixel Formats - Base API for pixel formats that have red, green, and blue channels.
- Rgb888 Pixel Formats
-
24-bit
^1RGB pixel format with three 8-bit channels. -
Rgba<
P, C> Pixel Formats - Base API for pixel formats that have red, green, blue, and alpha channels.
Mixins
-
Grayscale<
P, C> Pixel Formats - A mixin for pixel formats that represent graysacle pixels.
Constants
- abgr8888 → const Abgr8888 Pixel Formats
- 32-bit ABGR pixel format with four 8-bit channels.
- argb8888 → const Argb8888 Pixel Formats
- 32-bit ARGB pixel format with four 8-bit channels.
- floatRgba → const FloatRgba Pixel Formats
- A 128-bit floating-point RGBA pixel format with four 32-bit channels.
- gray8 → const Gray8 Pixel Formats
- 8-bit grayscale pixel format.
- rgb888 → const Rgb888 Pixel Formats
-
24-bit
^1RGB pixel format with three 8-bit channels.
Properties
-
system256
→ IndexedFormat<
int> Pixel Formats -
A simple 256-color system palette of common RGB colors.
final
-
system8
→ IndexedFormat<
int> Pixel Formats -
A simple 8-color system palette of common RGB colors.
final